<!DOCTYPE html>
<html>
<head>
<title>上传 - {config[webname]} - {config[webtitle]}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{config[keyword]}">
<script type="text/javascript" src="js/jquery-ui-1.8.16/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>

<link rel="stylesheet" type="text/css" href="js/jquery-ui-1.8.16/jquery-ui-1.8.16.custom.css" />

<link rel="stylesheet" type="text/css" href="styles/common.css" />
<link rel="stylesheet" type="text/css" href="styles/elements.css" />
<link rel="stylesheet" type="text/css" href="styles/table.css" />
<script type="text/javascript">
$(document).ready(function(){
	//$("#s1").hide("blind");
	//$("#s2").hide("blind");
	//$("#s3").show("blind");
});
function goStep2(lx){
		$("#lx").val(lx);
		$("#s1 .f2_content").hide("blind");
		$("#s2 .div-resource").hide();
		if(lx=="torrent"){
			$("#s2 #div-torrent").show();
			$("#s2 .f2_header").text("第二步：上传种子文件");
		}else if(lx=="ed2k"){
			$("#s2 #div-ed2k").show();
			$("#s2 .f2_header").text("第二步：设置电驴链接");
		}else if(lx=="magnet"){
			$("#s2 #div-magnet").show();
			$("#s2 .f2_header").text("第二步：设置磁力链接");
		}else if(lx=="thunder"){
			$("#s2 #div-thunder").show();
			$("#s2 .f2_header").text("第二步：设置迅雷链接");
		}
		$("#s2").show("blind");
}
function torrentselected(fileobj){
	var filepath = fileobj.value;
	if(filepath==null || filepath.length==0){
		return;
	}
	var reg = /\.torrent$/;
	if(!filepath.toLowerCase().match(reg)){
		alert("请选择torrent文件");
		return;
	}
	var objarr = $("#s2 #div-torrent .btfile");
	$.each(objarr,function(i,n){
		if(n.value!=null && n.value.length>0 && n!=fileobj && n.value==fileobj.value){
			alert("已经存在同名文件");
			$(n).effect("highlight");
			fileobj.value=""; 
			return false;
		}
	});
	var name = getFileNameWithOutSuffix(fileobj.value);
	$(fileobj).parents(".torrent-item").find(".btname").val(name);
}
function getFileNameWithOutSuffix(filepath){
	if(filepath==null || filepath.length<=0)return "";
	var t1 = filepath.lastIndexOf("\\");
	if(t1<0){
		t1=0;
	}
	var t2 = filepath.lastIndexOf(".");
	if(t1 >= 0 && t1 < t2 && t1 < filepath.length){
	 	return filepath.substring(t1 + 1, t2);
	}
}
function getFileName(filepath){
	if(filepath==null || filepath.length<=0)return "";
	var t1 = filepath.lastIndexOf("\\");
	if(t1 < filepath.length){
	 	return filepath.substring(t1 + 1);
	}
}
function addresource(){
	var lx = $("#lx").val();
	if(lx=="torrent"){
		var div = $($(".torrent-item")[0]).clone(true);
		div.find("input.btname").val("");
		div.find(".uploadnamediv").append($("<a class='removebtn btn' href='#u' onclick='removebt(this)'>删除</a>"));
		$("#torrent-list").append(div);
	}else if(lx=="ed2k"){
		var div = $($(".ed2k-item")[0]).clone(true);
		div.find("input.ed2k_name").val("");
		div.find("textarea.ed2k_link").val("");
		$("#ed2k-list").append(div);
		div.append($("<a class='removebtn btn' href='#u' onclick='removeed2k(this)'>删除</a>"));
		div.find("textarea.ed2k_link").focus();
	}else if(lx=="magnet"){
		var div = $($(".magnet-item")[0]).clone(true);
		div.find("input.magnet_name").val("");
		div.find("textarea.magnet_link").val("");
		$("#magnet-list").append(div);
		div.append($("<a class='removebtn btn' href='#u' onclick='removemagnet(this)'>删除</a>"));
		div.find("textarea.magnet_link").focus();
	}else if(lx=="thunder"){
		var div = $($(".thunder-item")[0]).clone(true);
		div.find("input.thunder_name").val("");
		div.find("textarea.thunder_link").val("");
		$("#thunder-list").append(div);
		div.append($("<a class='removebtn btn' href='#u' onclick='removemagnet(this)'>删除</a>"));
		div.find("textarea.thunder_link").focus();
	}
}
function removebt(obj){
	$(obj).parents(".torrent-item").remove();
}
function removeed2k(obj){
	$(obj).parent().remove();
}
function removemagnet(obj){
	$(obj).parent().remove();
}
function goStep3(){
	var lx = $("#lx").val();
	var names = new Array();
	if(lx=="torrent"){
		var arr_obj_itemobj = $("#s2 #div-torrent .torrent-item");
		for(i=0;i<arr_obj_itemobj.length;i++){
			var obj_item = arr_obj_itemobj[i];
			if($(obj_item).find(".btfile").val().length==0){
				alert("请选择种子文件！");
				$(obj_item).find(".torrent_uploadbtn").effect("highlight");
				return;
			}
			var btname = $(obj_item).find(".btname").val();
			if(btname.length==0){
				alert("请填写种子名称！");
				$(obj_item).find(".btname").focus();
				$(obj_item).find(".btname").effect("highlight");
				return;
			}
			names.push(btname);
		}
		if(names.length==0){
			alert("请至少添加一个BT资源!");
			return;
		}
	}else if(lx=="ed2k"){
		var arr_obj_itemobj = $("#s2 #div-ed2k .ed2k-item");
		for(i=0;i<arr_obj_itemobj.length;i++){
			var obj_item = arr_obj_itemobj[i];
			
			var obj_link = $(obj_item).find(".ed2k_link");
			if(obj_link.val().length==0){
				alert("请填写电驴链接！");
				obj_link.focus();
				obj_link.effect("highlight");
				return;
			}
			if(!v_ed2k_link(obj_link.val())){
				alert("链接地址无效，请检查！");
				obj_link.focus();
				obj_link.effect("highlight");
				return;
			}

			var obj_name = $(obj_item).find(".ed2k_name");
			if(obj_name.val().length==0){
				alert("请填写资源名称！");
				obj_name.focus();
				obj_name.effect("highlight");
				return;
			}
			names.push(obj_name.val());
		}
	}else if(lx=="magnet"){
		var arr_obj_itemobj = $("#s2 #div-magnet .magnet-item");
		for(i=0;i<arr_obj_itemobj.length;i++){
			var obj_item = arr_obj_itemobj[i];
			
			var obj_link = $(obj_item).find(".magnet_link");
			if(obj_link.val().length==0){
				alert("请填写磁力链接！");
				obj_link.focus();
				obj_link.effect("highlight");
				return;
			}
			if(!v_magnet_link(obj_link.val())){
				alert("链接地址无效，请检查！");
				obj_link.focus();
				obj_link.effect("highlight");
				return;
			}

			var obj_name = $(obj_item).find(".magnet_name");
			if(obj_name.val().length==0){
				alert("请填写资源名称！");
				obj_name.focus();
				obj_name.effect("highlight");
				return;
			}
			names.push(obj_name.val());
		}
	}else if(lx=="thunder"){
		var arr_obj_itemobj = $("#s2 #div-thunder .thunder-item");
		for(i=0;i<arr_obj_itemobj.length;i++){
			var obj_item = arr_obj_itemobj[i];
			
			var obj_link = $(obj_item).find(".thunder_link");
			if(obj_link.val().length==0){
				alert("请填写迅雷链接！");
				obj_link.focus();
				obj_link.effect("highlight");
				return;
			}
			if(!v_thunder_link(obj_link.val())){
				alert("链接地址无效，请检查！");
				obj_link.focus();
				obj_link.effect("highlight");
				return;
			}

			var obj_name = $(obj_item).find(".thunder_name");
			if(obj_name.val().length==0){
				alert("请填写资源名称！");
				obj_name.focus();
				obj_name.effect("highlight");
				return;
			}
			names.push(obj_name.val());
		}
	}
	for(var i=0;i<names.length;i++){
		var name = names[i];
		$("#name-list").append("<div>"+(i+1)+".&nbsp;"+name+"</div>");
	}
	$("#s2 .f2_content,#s2 .f2_btn").hide("blind");
	$("#s3").show("blind");
}
function v_link(link,regexp){
	link = link.trim();
	var reg = new RegExp(regexp);
	if(reg.test(link)){
		return true;
	}else{
		return false;
	}
}
function v_ed2k_link(link){
	return v_link(link,"^ed2k://\\|file\\|.+\\|\\d+\\|.*/$","i");
}
function v_magnet_link(link){
	return v_link(link,"^magnet:\\?.*$");
}
function v_thunder_link(link){
	return v_link(link,"^thunder:\\/\\/.+$");
}
function backStep2(){
	$("#s3 #name-list").empty();
	$("#s2 .f2_content,#s2 .f2_btn").show("blind");
	$("#s3").hide("blind");
}
function publish2(){
	if($("#desc").val().length>140){
		alert("资源描述不得超过140个字！");
		return false;
	}
	if($("#picdiv li").size()>5){
		alert("图片介绍不打超过5个！");
		return false;
	}
	$("#loading").openDialog({showHeader:false});
	return true;
}
function descchanged(){
	var left = 140-$("#desc").val().length;
	if(left<0){
		$("#desccount").html("还剩<b style='color:red'>"+left+"</b>个字");
	}else{
		$("#desccount").html("还剩<b>"+left+"</b>个字");
	}
}
function backStep1(){
	$("#s1 .f2_content").show("blind");
	$("#s2").hide("blind");
}
function link_changed(obj){
	if(obj.value.trim().length==0){
		$(obj).parent().parent().parent().find(".link_name").val("");
		return;
	}
	var lx = $("#lx").val();
	if(lx=="ed2k" || lx=="magnet" || lx=="thunder"){
		var arr_obj_link = $(obj).parent().parent().parent().parent().find(".link_link");
		for(i=0;i<arr_obj_link.length;i++){
			var obj_link = arr_obj_link[i];
			if(obj_link!=obj && obj_link.value.trim()==obj.value.trim()){
				alert("存在相同资源！");
				$(obj_link).effect("highlight");
				obj.value="";
				return false;
			}
		}
		
	}
	if(lx=="ed2k" && v_ed2k_link(obj.value)){
		var link = obj.value.trim();
		var from = "ed2k://|file|".length;
		var to = link.indexOf("|",from);
		var name = decodeURI(link.substring(from,to));
		$(obj).parent().parent().parent().find(".ed2k_name").val(name);
	}else if(lx=="magnet" && v_magnet_link(obj.value)){
		var link = obj.value.trim();
		var from = link.indexOf("dn=");
		if(from>0){
			from = from+3;
			var to = link.indexOf("&",from);
			var name = "";
			if(to>0){
				name = decodeURI(link.substring(from,to));
			}else{
				name = decodeURI(link.substring(from));
			}
			$(obj).parent().parent().parent().find(".magnet_name").val(name);
		}
	}
}
function addpic(){
	$("<li><input class='input_pic' type='file' name='pic[]' onchange='pic_setted(this)'><button onclick='$(this).parent().remove();'>删除</button</li>").appendTo("#picdiv");
}
function pic_setted(pic){
	var reg = /\.(jpg|png|gif)$/;
	var filepath = pic.value.trim();
	if(filepath.length>0){
		if(!filepath.toLowerCase().match(reg)){
			alert("请选择图片文件!");
			$(pic).replaceWith("<input class='input_pic' type='file' name='pic[]' onchange='pic_setted(this)'>");
			return false;
		}
	}
}
</script>
<style>
#picdiv li{
	margin-top:5px;
}
#picdiv input,#picdiv button{
	padding:0px 4px;
	height:26px;
	line-height:24px;
	vertical-align:middle;
}
#picdiv .input_pic{
	width:500px;
}
#picdiv button{
	cursor:pointer;
}
#picdiv button{
	margin-left:5px;
}
.f2{
	border:2px solid #6FBCEA;
}
.f2_header{
	background-color:#6FBCEA;
	color:white;
	padding:5px;
	font-size:14px;
	font-weight:bold;
}
.f2_content{
	padding:5px;
}
.f2_btn{
	text-align:center;
	padding:10px;
}
.s{
	margin-top:20px;
}
#s1 .f2_content{
	padding-top:20px;
	padding-bottom:20px;
}

#s1 .f2_content a img{
	width:40px;
	vertical-align:middle;
	height:40px;
	border:none;
	padding-right:10px;
}
#s1 .f2_content a{
	padding-left:50px;
	display:block;
	width:200px;
	height:50px;
	line-height:50px;
	font-size:20px;
	margin:20px auto;
	background-color:#EDF5F9;
	border:1px solid #f3f3f3;
	text-decoration:none;
}
#s1 .f2_content a:hover{
	background-color:#6FBCEA;
}
#s2{
	display:none;
}
#s2 .f2_content{
	padding:20px;
}
#s2 #div-torrent{
	margin-left:80px;
}
#s2 #div-torrent .uploadbtndiv{
	position:relative;
	float:left;
	overflow:hidden;
	width:104px;
	height:35px;
}
#s2 #div-torrent .uploadbtndiv .torrent_uploadbtn{
	position:relative;
	display:inline-block;
 	background-color:#6FBCEA;
 	border:none;
 	color:white;
 	font-size:14px;
 	padding:5px;
 	font-weight:bold;
}
#s2 #div-torrent .uploadbtndiv .torrent_uploadbtn:hover{
	cursor:pointer;
}
#s2 #div-torrent .uploadbtndiv .torrent_uploadbtn .btfile{
	display:block;
	position:absolute;
	top:0;
	left:0;
	width:104px;
	height:35px;
	cursor: pointer;
	background-color:red;
	font-size:200px;
	opacity: 0;  
	filter:alpha(opacity: 0);
}
#s2 #div-torrent .uploadnamediv .btname{
	height:30px;
	line-height:30px;
	font-size:18px;
	margin-left:5px;
	width:500px;
	border:1px solid #6FBCEA;
	padding-left:5px;
}
#s2 #div-torrent .removebtn{
	display:inline-block;
	padding:2px 5px;
	margin-left:5px;
}
#s2 .f2_btn a{
	margin:5px;
}
#s3{
	margin-bottom:50px;
	display:none;
}
#s3 .f2_content .label{
	width:100px;
	font-size:14px;
	font-weight:bold;
	text-align:right;
	float:left;
}
#s3 .f2_content .value{
	float:left;
	margin-left:10px;
}
#s3 .f2_content #desc{
	width:500px;
	height:100px;
	padding:5px;
}
#s3 .f2_content #tags{
	width:500px;
	padding:5px;
	
}
#s3 .f2_btn a{
	margin:5px;
}
a.prev-step-btn{
	background-color:#efefef;
	color:gray;
}
#s3 .f2_content #desccount{
	vertical-align:top;
	color:gray;
	padding-left:5px;
}
#s3 .f2_content #desccount b{
	vertical-align:top;
	color:black;
	font-size:14px;
	padding:0px 2px;
}
.tb-map{
}
.tb-map-row{
	clear:both;
	padding:2px 5px;
}
.tb-map-label{
	display:inline-block;
	width:60px;
	height:30px;
	text-align:right;
	color:gray;
	vertical-align:top;
	margin-right:10px;
}
.tb-map-value{
	display:inline-block;
	vertical-align:top;
}
#s2 .div-link .link-item{
	position:relative;
	border-left:2px solid #6FBCEA;
	background-color:#E1F3FC;
	width:600px;
	margin:5px auto;
	padding:10px 0px;
	border-right:1px solid #DFDFDF;
	border-top:1px solid #DFDFDF;
	border-bottom:1px solid #DFDFDF;
}
#s2 .div-link .link-item .link_link{
	width:498px;
	height:58px;
	padding:2px;
}
#s2 .div-link .link-item .link_name{
	width:500px;
	height:30px;
}
#s2 .div-link .link-item .removebtn{
	position:absolute;
	top:0px;
	left:605px;
	padding:2px 5px;
}
.btn,.btn_n{
	line-height:normal;
	padding:6px;
}
</style>
</head>
<body>
<!--#include file="header.html"-->
<form action="publish.php" method="post" id="myform" enctype="multipart/form-data" onsubmit="return publish2();">
<input type="hidden" id="lx" name="lx">
<input type="hidden" name="type" value="0">
<div id="s1" class="f2 s">
	<div class="f2_header">第一步：选择资源类型</div>
	<div class="f2_content">
		<a href="#u" onclick="goStep2('torrent')"><img class="resimg" src="{config[weburl]}/resource/res_torrent_50.png">BT资源</a>
		<a href="#u" onclick="goStep2('ed2k')"><img class="resimg" src="{config[weburl]}/resource/res_ed2k_50.png">电驴链接</a>
		<a href="#u" onclick="goStep2('magnet')"><img class="resimg" src="{config[weburl]}/resource/res_magnet_50.png">磁力链接</a>
		<a href="#u" onclick="goStep2('thunder')"><img class="resimg" src="{config[weburl]}/resource/res_thunder_50.png">迅雷链接</a>
	</div>
</div>
<div id="s2" class="f2 s">
	<div class="f2_header">第二步</div>
	<div class="f2_content">
		<div id="div-torrent" class="div-resource div-link">
			<div id="torrent-list">
				<div class="torrent-item">
					<div class="uploadbtndiv">
						<span class="torrent_uploadbtn">选择种子文件<input onchange="torrentselected(this)" type="file" name="btfile[]" class="btfile" title="支持.torrent文件"></span>
					</div>
					<div class="uploadnamediv"><input class="btname uploadnamediv" name="btname[]" maxlength="200"></div>
					<br style="clear:both">
				</div>
			</div>
		</div>
		<div id="div-ed2k" class="div-resource div-link">
			<div id="ed2k-list" class="link-list">
				<div class="tb-map ed2k-item link-item">
					<div class="tb-map-row">
						<div class="label tb-map-label">电驴链接</div>
						<div class="value tb-map-value"><textarea name="ed2k_link[]" class="ed2k_link link_link" onchange="link_changed(this)" maxlength="5000"></textarea></div>
					</div>
					<div class="tb-map-row">
						<div class="label tb-map-label">资源名称</div>
						<div class="value tb-map-value"><input name="ed2k_name[]" class="ed2k_name link_name" maxlength="200"></div>
					</div>
				</div>
			</div>
		</div>
		<div id="div-magnet" class="div-resource div-link">
			<div id="magnet-list" class="link-list">
				<div class="tb-map magnet-item link-item">
					<div class="tb-map-row">
						<div class="label tb-map-label">磁力链接</div>
						<div class="value tb-map-value"><textarea name="magnet_link[]" class="magnet_link link_link" onchange="link_changed(this)" maxlength="5000"></textarea></div>
					</div>
					<div class="tb-map-row">
						<div class="label tb-map-label">资源名称</div>
						<div class="value tb-map-value"><input name="magnet_name[]" class="magnet_name link_name" maxlength="200"></div>
					</div>
				</div>
			</div>
		</div>
		<div id="div-thunder" class="div-resource div-link">
			<div id="thunder-list" class="link-list">
				<div class="tb-map thunder-item link-item">
					<div class="tb-map-row">
						<div class="label tb-map-label">迅雷链接</div>
						<div class="value tb-map-value"><textarea name="thunder_link[]" class="thunder_link link_link" onchange="link_changed(this)" maxlength="5000"></textarea></div>
					</div>
					<div class="tb-map-row">
						<div class="label tb-map-label">资源名称</div>
						<div class="value tb-map-value"><input name="thunder_name[]" class="thunder_name link_name" maxlength="200"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="f2_btn">
		<a class="btn_n" href="#u" onclick="backStep1()">上一步</a>
		<a class="btn" href="#u" onclick="addresource()">添&nbsp;加</a>
		<a class="btn" href="#u" onclick="goStep3()">下一步</a>
	</div>
</div>
<div id="s3" class="f2 s">
	<div class="f2_header">第三步：添加描述</div>
	<div class="f2_content">
		<div class="label">列表</div>
		<div class="value"><div id="name-list"></div></div>
		<div style="clear:both;height:20px"></div>
		<div class="label">描述</div>
		<div class="value"><textarea id="desc" name="desc" onkeyup="descchanged()" maxlength="500"></textarea><span id="desccount">还剩<b>140</b>个字</span></div>
		<div style="clear:both;height:20px"></div>
		<div class="label">标签</div>
		<div class="value"><input id="tags" name="tags" maxlength="500"><font color="gray">&nbsp;&nbsp;多个话题用空格分割</font></div>
		<div style="clear:both;height:20px"></div>
		<div class="label">&nbsp;</div>
		<div class="value">
			<a href="javascript:addpic()" style="line-height:24px;font-size:14px;">[+]添加图片介绍</a>（不超过5张，单张图片大小&lt;5M，支持JPG、GIF、PNG格式）
			<ul id="picdiv"></ul>
		</div>
		<div style="clear:both;height:20px"></div>
		<!-- if($oauth_tencent_info) -->
		<div class="label">&nbsp;</div>
		<div class="value">
			<input type="checkbox" name="publish_tencent" checked="checked">发布到腾讯微博
		</div>
		<div style="clear:both;height:20px"></div>
		<!-- end -->
	</div>
	<div class="f2_btn">
		<a class="btn_n" href="#u" onclick="backStep2()">上一步</a>
		<input class="btn" type="submit" name="publish" value="发&nbsp;布">
	</div>
</div>
</form>
<div style="height:100px"></div>
<div id="loading" style="display:none;padding:20px;">发布中，请稍候。。。</div>
</body>
</html>